
mBox <- melt(df, c("survey"), c("ipl12s", "ipl24s", "yearsIn"))
resid <- subset(mBox, variable == "yearsIn")
mBox <- subset(mBox, variable != "yearsIn")

mBox$instr <- ifelse(grepl("12", mBox$variable), "IPL-12", "IPL-24")
mBox$instr <- as.factor(mBox$instr)

ipl12box <- ggplot(subset(mBox, instr = "IPL-12"), aes(x = survey, y = value, fill = survey)) +
  geom_boxplot(width = .4, varwidth = TRUE, size = .5, outlier.size = .3) +
  coord_cartesian(ylim = c(0, 1)) +
  scale_fill_manual(values = Col3) +
  ylab("IPL-12 Integration Index") +
  xlab("Samples") +
  theme_minimal() +
  guides(fill = FALSE) +
  scale_x_discrete(labels = c("YouGov" = "A",
                              "Germany" = "B", 
                              "NewYork" = "C",
                              "Allies" = "D")) +
  theme(axis.title = element_text(size = 10),
        axis.text = element_text(size = 9),
        plot.title = element_text(size = 10),
        legend.position = "none")

displayItme1both <- ggplot(mBox, aes(x = survey, y = value, fill = survey, linetype = instr)) +
  geom_boxplot(width = .4, varwidth = TRUE, size = .5, outlier.size = .3) +
  coord_cartesian(ylim = c(0, 1)) +
  scale_fill_manual(values = Col3) +
  ylab("IPL Integration Index Scores") +
  xlab("Samples") +
  theme_minimal() +
  guides(fill = FALSE) +
  scale_x_discrete(labels = c("YouGov" = "A",
                              "Germany" = "B", 
                              "NewYork" = "C",
                              "Allies" = "D")) +
  theme(axis.title = element_text(size = 10),
        axis.text = element_text(size = 9),
        plot.title = element_text(size = 10),
        legend.position = "right",
        legend.title  = element_blank())

# Box plot for residency
residBox <- ggplot(resid, aes(x = survey, y = value, fill = survey)) +
  geom_boxplot(width = .4, varwidth = TRUE, size = .5, outlier.size = .3) +
  #coord_cartesian(ylim = c(0, 1)) +
  scale_fill_manual(values = Col3) +
  ylab("Years of Residency") +
  xlab("Samples") +
  theme_minimal() +
  guides(fill = FALSE) +
  scale_x_discrete(labels = c("YouGov" = "A",
                              "Germany" = "B", 
                              "NewYork" = "C",
                              "Allies" = "D")) +
  theme(axis.title = element_text(size = 10),
        axis.text = element_text(size = 9),
        plot.title = element_text(size = 10),
        legend.position = "none")

# Saved with Lichtenberg Ratio (A4)
display1 <- arrangeGrob(residBox, ipl12box, nrow = 1)
ggsave(here::here("Draft/PNAS/draft/plots", "displayItem1.pdf"), display1, height = (17.8 / 2.76), width = 17.8, units = "cm")
ggsave(here::here("Draft/PNAS/draft/plots", "displayItem1both.pdf"), displayItme1both, height = (17.8 / 2), width = 17.8, units = "cm")

